package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.SingleChoiceAnswer;
import com.yami.shop.bean.model.SingleChoiceQue;
import com.yami.shop.dao.SingleChoiceQueMapper;
import com.yami.shop.service.SingleChoiceAnswerService;
import com.yami.shop.service.SingleChoiceQueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 灯谜问题
 */

@Service
public class SingleChoiceQueServiceImpl extends ServiceImpl<SingleChoiceQueMapper, SingleChoiceQue> implements SingleChoiceQueService {

    @Autowired
    private SingleChoiceAnswerService singleChoiceAnswerService;

    @Override
    public SingleChoiceQue getQueDetail(String queIds) {
        QueryWrapper<SingleChoiceQue> singleChoiceQueQueryWrapper = new QueryWrapper<>();
        singleChoiceQueQueryWrapper.in("id",queIds);
        singleChoiceQueQueryWrapper.last(" ORDER BY RAND() LIMIT 1");
        SingleChoiceQue one = this.getOne(singleChoiceQueQueryWrapper);
        // 获取答案信息
        List<SingleChoiceAnswer> ques = singleChoiceAnswerService.list(new QueryWrapper<SingleChoiceAnswer>().eq("que_id", one.getId()));
        one.setSingleChoiceAnswers(ques);
        return one;
    }
}
